#ifndef LOG_APPENDER_H
#define LOG_APPENDER_H
#include "log_monitor.h"
#include "appender_config.h"
#include <boost/shared_ptr.hpp>

namespace vpm
{
	namespace log 
	{
		namespace detail
		{
			class LogAppender
			{
            public:
                LogAppender(boost::shared_ptr<AppenderConfig>  cfg,
                            int loggerType = LogConfig::LOGGER_NULL):m_loggerType(loggerType)
                {
                    m_appenderConfig = cfg; 
                }

				virtual ~LogAppender()
				{
				}

				virtual int open()
				{
					return 0; 
				}

				virtual void close()
				{

				}

				void append_message(LogMessageBlock * pLogMsg)
                {
                    if (pLogMsg->logger_type() & m_loggerType)
                    {
                        this->do_append(pLogMsg);
                        pLogMsg->clear_flag(m_loggerType);
                        if (pLogMsg->logger_type() ==0 )
                        {
                            LogMonitor::instance().message_pool().release_message_block(pLogMsg);
                        }
                    }		
                }

				virtual void do_append(LogMessageBlock * pLogMsg)=0;

			protected:
				int m_loggerType;
                boost::shared_ptr<AppenderConfig> m_appenderConfig; 

			};
		}
	}
}



#endif // 
     
